import axios from '@/utils/request'

/**
 * 获取评论列表
 * @param {*} id 文章id
 * @param {*} offset
 * @returns
 */
export function getComment (id, offset) {
  return axios({
    method: 'GET',
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: id,
      offset
    }
  })
}

/**
 * 添加评论
 * @param {*} id 文章id
 * @param {*} content 评论内容
 * @returns
 */
export function addComment (id, content) {
  return axios({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: id,
      content
    }
  })
}

/**
 * d对评论点赞
 * @param {*} id 评论id
 * @returns
 */
export function likeComment (id) {
  return axios({
    method: 'post',
    url: '/v1_0/comment/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消对评论的点赞
 * @param {*} id 评论的id
 * @returns
 */
export function disLikeComment (id) {
  return axios({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + id
  })
}

/**
 * 获取评论回复列表
 * @param {*} id 当前评论id
 * @param {*} offset
 * @returns
 */
export function getReplyComment (id, offset) {
  return axios({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source: id,
      offset
    }
  })
}

export function addReplyComment (id, content, articleId) {
  return axios({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: id,
      content,
      art_id: articleId
    }
  })
}
